<template>
	<view class="content"  :style="{height: tabHeightVal}">
		<view class="dataUpdata">
			<view class="list" v-for="(item, index) in list" :key="index">
				<view class="liview" style="float: left;">
					<view class="pview" style="float:left;width: 100%;">
						<view class="ispan" style="font-size:46rpx;float:left;min-width: 100%;">
						{{item.name}}
						</view>

					</view>
					<view class="footer row" style="padding: 20rpx 0;float:left;width: 100%;">
						<view class="ispan" style="font-size:28rpx;width: 76% !important;color: #BEBEBE;float: left;border-bottom: 1px #bfbfbf solid;padding-bottom: 15rpx;">{{item.date}}</view>
						<view class="ispan" style="font-size:28rpx;width: 20% !important;color: #BEBEBE;float: left;">
							<view class="button" @click.stop="confirm(2,$event)" :data-id="item.name">更新</view>
							<!--<view class="button" style="border-left: 1px #FFFFFF solid;" @tap="datasynlocalclear($event)" :data-Id="item.name">清除</view>-->
						</view>

					</view>
				</view>
			</view>

		</view>
		<aui-dialog
			ref="dialog"
			:title="auiDialog.title"
			:msg="auiDialog.msg"
			:btns="auiDialog.btns"
			:mask="auiDialog.mask"
			:maskTapClose="auiDialog.maskTapClose"
			:items="auiDialog.items"
			:theme="auiDialog.theme"
			@callback="dialogCallback"
		></aui-dialog>
	</view>
</template>

<script>
	import {
		openComDB,
		executeSQL,
		executeSQLNew,
		beginTransaction,
		commitTransaction,
		dropSQL
	} from "@/pages/API/sqllite/sqllite.js";
	import {aui} from '@/common/aui/js/aui.js';
	import auiDialog from '@/components/aui-dialog/aui-dialog.vue';
	var self;
	export default {
		components: {
				
		},
		data() {
			return {
				list: [
					/*{
						name: "资产台账同步",
						date: "从未更新",
						index: "0"
					},*/
					{
						name: "盘点单下载",
						date: "从未更新",
						index: "1"
					},
					{
						name: "位置信息下载",
						date: "从未更新",
						index: "2"
					}
				],
				loginName: "",
				currName:"",
				contentHeight: null,
				auiDialog: {
					title: '',
					msg: '',
					btns: [{name: '确定'}],
					mask: true,
					maskTapClose: true,
					items: [],
					theme: 1,
				},
			}
		},
		computed: {
			tabHeightVal() {
				return (uni.getSystemInfoSync().windowHeight) + 'px'
			}
		},
		onLoad() {
			self = this;
			const listdata = uni.getStorageSync("userinfo");
			self.loginName = listdata.LoginName;
			console.log(1111111);
			this.getNetworkType(); //初始化网络当前状态
			uni.getStorage({
				key: "盘点数据同步",
				success: function(newres) {
					self.list[0].date = newres.data;
				}
			});
			uni.getStorage({
				key: "资产位置同步",
				success: function(newres) {
					self.list[1].date = newres.data;
				}
			});
			//uni.getStorage({
			//	key: "资产数据同步",
			//	success: function(newres) {
			//		self.list[0].date = newres.data;
			//	}
			//});
			
			
		},
		onBackPress(options) {
			// console.log(options);
			if(uni.getStorageSync("shuaxinDate")=="1"){
				uni.setStorageSync("shuaxinDate","0");
				uni.setStorageSync("homebackDate","1");
				uni.navigateTo({
					url: '../home/home',
					animationType: 'slide-in-left',
					animationDuration: 400,
					success(res) {
						console.log('跳转成功', res)
					},
					fail: (err) => {
						console.log('跳转失败', err)
					}
				});
				return true;
			}else{
				
				return false;
			}
			

			// return true 表示禁止默认返回
			
			// return false;  
		},
		methods: {
			getTime: function() {

				var date = new Date(),
					year = date.getFullYear(),
					month = date.getMonth() + 1,
					day = date.getDate(),
					hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
					minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
					second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
				return timer;
			},
			datasynlocal(e) {
				
				if (e.currentTarget.dataset.id == "盘点单下载") {
					this.dataStock();
				}
				if (e.currentTarget.dataset.id == "位置信息下载") {
					this.dataStore();
				}
				if (e.currentTarget.dataset.id == "资产台账同步") {
					this.dataAsset();

				}
			},
			datasynlocalclear(e) {
				self = this;
				console.log(e.currentTarget.dataset.id);
				var dtaxt = "";
				if (e.currentTarget.dataset.id == "盘点单下载") {
					dtaxt = "盘点数据";
				}
				if (e.currentTarget.dataset.id == "位置信息下载") {
					dtaxt = "资产位置";
				}
				if (e.currentTarget.dataset.id == "资产台账同步") {
					dtaxt = "资产数据";
				}
				uni.showModal({

					title: '数据清除',
					content: '是否清除' + dtaxt,
					success: function(res) {
						if (res.confirm) {
							if (e.currentTarget.dataset.id == "盘点单下载") {
								executeSQL('nfc', 'delete FROM MybuildTable', res2 => {})
								executeSQL('nfc', 'delete FROM buildDetailTable', res2 => {})
								uni.removeStorage({
									key: "盘点数据同步",
									success: function(res) {
										self.list[0].date = "从未更新";
									}
								});

							} else if (e.currentTarget.dataset.id == "位置信息下载") {
								executeSQL('nfc', 'delete FROM buildStore', res2 => {})
								uni.removeStorage({
									key: "资产位置同步",
									success: function(res) {
										self.list[1].date = "从未更新";
									}
								});

							} else if (e.currentTarget.dataset.id == "资产台账同步") {
								executeSQL('nfc', 'delete FROM buildAsset', res2 => {})
								uni.removeStorage({
									key: "资产数据同步",
									success: function(res) {
										self.list[0].date = "从未更新";
									}
								});
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			createBuildTable() {
				//SQLite      
				openComDB('nfc', '_doc/nfcList.db', res => {
					console.log('打开数据库');
				});
				
				uni.setStorage({
					key: 'SaveStockDocumentCode',
					data: ''
				});
				
	//创建盘点单表；
	var sqlTable =
		'drop table MybuildTable'
	executeSQL('nfc', sqlTable, res => {
		console.log(res);
		
	})
				
				//创建盘点单表；
				var sqlTable =
					'create table if not exists MybuildTable("Id" CHAR,"Code" CHAR,"StockCheckTaskCode" CHAR,"StockCheckResult" CHAR,"TaskFinished" CHAR,"IsUploaded" CHAR,"loginName" CHAR,"DocumentStr3" CHAR,"StartDeadline" CHAR,"Deadline" CHAR,"盘点单名称" CHAR,"盘点任务" CHAR,"盘点人" CHAR,"制定人" CHAR,"制定日期" CHAR,"未盘" CHAR,"正常" CHAR,"盘亏" CHAR,"异常" CHAR,"盘盈" CHAR,"盘点总数" CHAR,"orgPosition" CHAR)'
				executeSQL('nfc', sqlTable, res => {})

//创建盘点单明细表；
			

				//创建盘点单明细表；
				var sqlTable2 =
					'create table if not exists buildDetailTable("Id" CHAR,"DocumentId" CHAR,"AssetId" CHAR,"StorePlaceId" CHAR,"PdStorePlaceId" CHAR,"Code" CHAR,"StoreCodeName" CHAR,"盘点单编码" CHAR,"资产编码" CHAR,"资产名称" CHAR,"资产类别" CHAR,"规格型号" CHAR,"数量" CHAR,"使用部门" CHAR,"使用人" CHAR,"盘点使用人" CHAR,"资产位置" CHAR,"盘点位置" CHAR,"盘点备注" CHAR,"盘点人" CHAR,"盘点状态" CHAR,"盘点结果" CHAR,"盘点日期" CHAR,"ImgUrl" CHAR,"TaskCount" CHAR,"isPhoto" CHAR)'
				executeSQL('nfc', sqlTable2, res => {})

				//资产位置；
				var sqlTable3 =
					'create table if not exists buildStore("value" CHAR)'
				executeSQL('nfc', sqlTable3, res => {})


				//创建资产表
				var sqlTable4 =
					'create table if not exists buildAsset("资产状态" CHAR,"入库单号" CHAR,"Id" CHAR,"Code" CHAR,"资产编码" CHAR,"财务编码" CHAR,"拆分前资产编码" CHAR,"财务条形码" CHAR,"申购单号" CHAR,"资产大类" CHAR,"资产小类" CHAR,"资产名称" CHAR,"资产位置" CHAR,"品牌" CHAR,"规格型号" CHAR,"资产序列号" CHAR,"数量" CHAR,"资产原值" CHAR,"资产净值" CHAR,"使用人" CHAR,"使用部门" CHAR,"管理部门" CHAR,"入库日期" CHAR,"购置日期" CHAR,"领用日期" CHAR,"报废日期" CHAR)'
				executeSQL('nfc', sqlTable4, res => {})
				
				
			},
			dataAsset() {
				self = this;
							uni.showNavigationBarLoading(); //显示加载动画
							//self.createBuildTable();
								console.log(888888);
								console.log(self.loginName);
							uni.request({
								url:uni.getStorageSync("localurl") + '/Report/APPAsset_Detail',
								data: {
									UserCode: self.loginName,
									pageSize: 20000,
									pageIndex: 0,
								},
								success: res2 => {
									//console.log(222);
									if (res2.data.successed == true) {
										console.log(res2);

										var mydata = [];
										var newrows = JSON.parse(res2.data.rows);
										for (var i = 0; i < newrows.length; i++) {
											var valueRows = newrows[i].toString().split(',');
											var datarow = {};
											for (var j = 0; j < res2.data.columns.length; j++) {
												datarow[res2.data.columns[j].字段名] = valueRows[j];
											}
											mydata.push(datarow);

										}
										
									   beginTransaction('nfc');
										executeSQL('nfc', 'delete FROM buildAsset', res2 => {})
										for (var i = 0; i < mydata.length; i++) {
											var sqlInsert = "insert into buildAsset values('";
											sqlInsert += mydata[i].资产状态 + "','";
											sqlInsert += mydata[i].入库单号 + "','";
											sqlInsert += mydata[i].Id + "','";
											sqlInsert += mydata[i].Code + "','";
											sqlInsert += mydata[i].资产编码 + "','";
											sqlInsert += mydata[i].财务编码 + "','";
											sqlInsert += mydata[i].拆分前资产编码 + "','";
											sqlInsert += mydata[i].财务条形码 + "','";
											sqlInsert += mydata[i].申购单号 + "','";
											sqlInsert += mydata[i].资产大类 + "','";
											sqlInsert += mydata[i].资产小类 + "','";
											sqlInsert += mydata[i].资产名称 + "','";
											sqlInsert += mydata[i].资产位置 + "','";
											sqlInsert += mydata[i].品牌 + "','";
											sqlInsert += mydata[i].规格型号 + "','";
											sqlInsert += mydata[i].资产序列号 + "','";
											sqlInsert += mydata[i].数量 + "','";
											sqlInsert += mydata[i].资产原值 + "','";
											sqlInsert += mydata[i].资产净值 + "','";
											sqlInsert += mydata[i].使用人 + "','";
											sqlInsert += mydata[i].使用部门 + "','";
											sqlInsert += mydata[i].管理部门 + "','";
											sqlInsert += mydata[i].入库日期 + "','";
											sqlInsert += mydata[i].购置日期 + "','";
											sqlInsert += mydata[i].领用日期 + "','";
											sqlInsert += mydata[i].报废日期 + "'";
											sqlInsert += ')';

											executeSQLNew('nfc', sqlInsert)
										}
										commitTransaction('nfc');
										 //console.log(22);

										var currtime = (self.getTime());
										uni.setStorage({
											key: "资产数据同步",
											data: currtime
										});
										self.list[0].date = currtime;
										uni.hideNavigationBarLoading();
										//console.log(333);
										//this.model = res.data.model;
									}else{
										uni.hideNavigationBarLoading();
										}
								},
								fail: () => {
									uni.hideNavigationBarLoading();
									uni.showToast({
										icon: 'none',
										title: '网络异常,请稍后重试'
									});
								}
							});
					
			},
			dataStore() {
				self = this;
				
				uni.showNavigationBarLoading();
				//self.createBuildTable();
				let managePositionIds = uni.getStorageSync("managePositionIds");
				console.error(managePositionIds);
				this.request_tool({
					url:'/console/app/v1/position/treeData',
					type:'POST',
					data:{}
				}).then(res => {
						console.error(res);
						if(res!=undefined){
						if (res.data.code == 2000) {
							console.log(res.data.data);
							let treedata= res.data.data;
							//let newtreedata=[];
							//self.filterParentNode(managePositionIds,treedata,newtreedata);
							//self.treelist=newtreedata;
							
							executeSQL('nfc', 'delete FROM buildStore', res2 => {})
							var sqlInsert = "insert into buildStore values('";
							sqlInsert += JSON.stringify(treedata) + "'";
							sqlInsert += ')';
							
							executeSQL('nfc', sqlInsert, res4 => {
							
							})
							var currtime = (self.getTime());
							uni.setStorage({
								key: "资产位置同步",
								data: currtime
							});
							self.list[1].date = currtime;
							uni.hideNavigationBarLoading();
							
							//this.model = res.data.model;
						}else{
							self.jieshumethed("请求失败");
						}
						}else{
							self.jieshumethed("请求超时");
						}
						}).catch(err => {
				  console.error(err);
				  self.jieshumethed(err);
				});
							
							
						

			},
			dataStock() {
				self = this;
							let userInfo = uni.getStorageSync("userInfo");
							
							
							uni.showNavigationBarLoading(); //显示加载动画
							this.createBuildTable();
							uni.removeStorageSync('StockDocumentData');
							console.log(self.loginName);
							console.log(JSON.parse(userInfo).id);
							let querydata={
									//"pageSize": 10,
									//"current": 0,
									manageUser:JSON.parse(userInfo).id
								};
							this.request_tool({
								url:'/console/app/v1/assetCheck/getCheckDocumentListAndTaskList',
								type:'POST', 
								data:querydata
							}).then(res => {
								console.log(res);
								
								//convertCheckDocumentList、盘点单信息
									//formatAssetCheckDetailMap  盘点单明细信息
									if(res!=undefined){
								if (res.data.code == 2000) {
									if(res.data.data!=null){
										let mydata=res.data.data.convertCheckDocumentList;
										var newiups="False";
										beginTransaction('nfc');
										executeSQL('nfc', 'delete FROM MybuildTable', res2 => {})
										executeSQL('nfc', 'delete FROM buildDetailTable', res2 => {})
										let ids=[];
										for (var i = 0; i < mydata.length; i++) {
											let assetCategoryPhoto=res.data.data.assetCheckTaskAppVoMap[mydata[i].taskId][0].assetCategoryPhoto;
											uni.setStorage({
												key:mydata[i].id+"assetCategoryPhoto",
												data:assetCategoryPhoto
											});
											ids.push(mydata[i].id);
											var sqlInsert = "insert into MybuildTable values('";
											sqlInsert += mydata[i].id + "','";
											sqlInsert += mydata[i].code + "','";
											sqlInsert += mydata[i].taskCode + "','";
											sqlInsert += mydata[i].checkResult + "','";
											sqlInsert += 0 + "','";
											sqlInsert +=  newiups+ "','";
											sqlInsert += mydata[i].createUser + "','";
											sqlInsert += mydata[i].DocumentStr3 + "','";
											sqlInsert += mydata[i].startDate + "','";
											sqlInsert += mydata[i].endDate + "','";
											sqlInsert += mydata[i].name + "','";
											sqlInsert += res.data.data.assetCheckTaskAppVoMap[mydata[i].taskId][0].name  + "','";
											//sqlInsert += mydata[i].盘点人 + "','";
											sqlInsert += mydata[i].checkUser + "','";										
											//sqlInsert += mydata[i].管理人 + "','";
											sqlInsert += mydata[i].createUser + "','";
											sqlInsert += mydata[i].createTime + "','";
											sqlInsert += mydata[i].nodoCount + "','";
											sqlInsert += mydata[i].normalCount + "','";
											sqlInsert += mydata[i].lossCount + "','";
											sqlInsert += mydata[i].errCount + "','";
											sqlInsert += mydata[i].surplusCount + "','";
											sqlInsert += mydata[i].totalCount + "','";
											sqlInsert += JSON.stringify(mydata[i].orgPosition) + "'";
											sqlInsert += ')';
										
											executeSQLNew('nfc', sqlInsert, res4 => {
										
											})
											//}
										}
										
										this.request_tool({
											url:'/console/app/v1/assetCheck/setAppCheckFinishFlag',
											type:'POST',
											data:{
												ids:ids,
												isAppCheckFinish:0
											}
										}).then(res2 => {
													console.error(res2);
													if (res2.data.code == 2000) {
															
														}else{
															uni.showModal({
															  title: '保存失败',
															  content:res2.data.msg,
															  showCancel: false
															});
														}
													}).catch(err2 => {
											  console.error(err2);
											  
											});
										console.log(123456789);
										commitTransaction('nfc');
										self.getLocDetailBuilds(res,1) //插入成功后，就可以查看结果。此处用到就直接赋值，没用到，或者别处用到，就在别处调用  
									
									}else{
										uni.showToast({
											icon: 'none',
											title: "暂无数据"
										});
										self.jieshumethed();
									}					 
								}else{
									uni.showToast({
										icon: 'none',
										title: "请求失败"
									});
									self.jieshumethed();
								}
								}else{
									uni.showToast({
										icon: 'none',
										title: "接口请求超时"
									});
									self.jieshumethed("接口请求超时");
								}
							}).catch(err => {
							  console.error(err);
							uni.showToast({
								icon: 'none',
								title: err
							});
							  self.getLocDetailBuilds(res,0)
							  
							});
							
							/*
							uni.request({
								url:uni.getStorageSync("localurl")+'/ServerAPI/APPUNIDocument_List_Query',
								data: {
									PdloginName: self.loginName,
									pageSize: 9999,
									_r: "813efd8e-1ac0-4cc8-8c35-3d502f680353",
									pageIndex: 0,
								},
								success: (res) => {
									
									if (res.data.successed == true) {
										
										var mydata = [];
										var newrows = JSON.parse(res.data.rows);

										for (var i = 0; i < newrows.length; i++) {
											var valueRows = newrows[i].toString().split(',');
											var datarow = {};
											for (var j = 0; j < res.data.columns.length; j++) {
												//alert(_data.columns[j].字段名)
												datarow[res.data.columns[j].字段名] = valueRows[j];
											}


											mydata.push(datarow);
										}
										console.log(mydata);
										uni.setStorage({
											key: 'StockDocumentData',
											data: mydata
										});
										
										var newiups="False";
										beginTransaction('nfc');
										executeSQL('nfc', 'delete FROM MybuildTable', res2 => {})
										executeSQL('nfc', 'delete FROM buildDetailTable', res2 => {})
										for (var i = 0; i < mydata.length; i++) {
											var sqlInsert = "insert into MybuildTable values('";
											sqlInsert += mydata[i].Id + "','";
											sqlInsert += mydata[i].Code + "','";
											sqlInsert += mydata[i].StockCheckTaskCode + "','";
											sqlInsert += mydata[i].StockCheckResult + "','";
											sqlInsert += mydata[i].TaskFinished + "','";
											sqlInsert +=  newiups+ "','";
											sqlInsert += mydata[i].loginName + "','";
											sqlInsert += mydata[i].DocumentStr3 + "','";
											sqlInsert += mydata[i].StartDeadline + "','";
											sqlInsert += mydata[i].Deadline + "','";
											sqlInsert += mydata[i].盘点单名称 + "','";
											sqlInsert += mydata[i].盘点任务 + "','";
											sqlInsert += mydata[i].盘点人 + "','";
											sqlInsert += mydata[i].管理人 + "','";
											sqlInsert += mydata[i].制定日期.substr(0,mydata[i].制定日期.indexOf(" ")) + "','";
											sqlInsert += mydata[i].未盘 + "','";
											sqlInsert += mydata[i].正常 + "','";
											sqlInsert += mydata[i].盘亏 + "','";
											sqlInsert += mydata[i].异常 + "','";
											sqlInsert += mydata[i].盘盈 + "','";
											sqlInsert += mydata[i].allCount + "'";
											sqlInsert += ')';

											executeSQLNew('nfc', sqlInsert, res4 => {

											})
											//}
										}
										console.log(123456789);
										commitTransaction('nfc');
										self.getLocDetailBuilds() //插入成功后，就可以查看结果。此处用到就直接赋值，没用到，或者别处用到，就在别处调用  
										
										
									}
								},
								fail: () => {
									//  请求失败,隐藏加载状态
									this.mescroll.endErr()
								}
							})
							*/
						
			},
			jieshumethed(error){
				var currtime = (self.getTime());
				uni.setStorage({
					key: "盘点数据同步",
					data: currtime
				});
				self.list[0].date = currtime;
				uni.hideNavigationBarLoading();
			},
			getLocDetailBuilds(res,current) {
				
				var mynum=0;
				let listdata=res.data.data.convertCheckDocumentList;
				//let mydatamap=res.data.data.formatAssetCheckDetailMap;
	
				//console.log(mydata);
				// var sqlTable2 = 'create table if not exists buildDetailTable("Id" CHAR,"AssetId" CHAR,"Code" CHAR,
				//"StoreCodeName" CHAR,"盘点单编码" CHAR,"资产编码" CHAR,"盘点人" CHAR,"盘点状态" CHAR,
				//"盘点结果" CHAR,"盘点日期" CHAR,"ImgUrl" CHAR)'
				//var SaveStockDocumentCode = uni.getStorageSync('SaveStockDocumentCode');
				let documentids=[];
				for (var j = 0; j < listdata.length; j++) {
					//let mydata=mydatamap[listdata[j].id];
					//console.log(listdata[j]);
					documentids.push(listdata[j].id);
					
				}
				
				let userInfo = uni.getStorageSync("userInfo");
				let querydata={
						"pageSize": 100,
						"current": current,
						manageUser:JSON.parse(userInfo).id,
						documentIds:documentids
					};
				this.request_tool({
					url:'/console/app/v1/assetCheck/getCheckDetailPageData',
					type:'POST', 
					data:querydata
				}).then(res2 => {
					//console.log(res2);
					
					//convertCheckDocumentList、盘点单信息
						//formatAssetCheckDetailMap  盘点单明细信息
						if(res2!=undefined){
					if (res2.data.code == 2000) {
						//console.log("页数:"+current+";同步数量:"+res2.data.data.records.length+";同步id:"+JSON.stringify(documentids));
						if(res2.data.data!=null){
							let mydata=res2.data.data.records;
							//records
							for (var i = 0; i < mydata.length; i++) {
								//console.log(mydata[i]);
								//if (SaveStockDocumentCode.indexOf(mydata[i].盘点单编码) == -1) {
									//console.log(mydata[i]);
									//'create table if not exists buildDetailTable(
									//"Id" CHAR,"AssetId" CHAR,"StorePlaceId" CHAR,"PdStorePlaceId" CHAR,"Code" CHAR,"StoreCodeName" CHAR,
									//"盘点单编码" CHAR,"资产编码" CHAR,"资产名称" CHAR,"资产类别" CHAR,"规格型号" CHAR,"数量" CHAR,"使用部门" CHAR,"使用人" CHAR,
									//"盘点使用人" CHAR,"资产位置" CHAR,"盘点位置" CHAR,"盘点备注" CHAR,"盘点人" CHAR,"盘点状态" CHAR,"盘点结果" CHAR,"盘点日期" CHAR,"ImgUrl" CHAR)'
									//executeSQL('nfc', 'delete FROM buildDetailTable where Id="' + mydata[i].Id + '"', res2 => {})
									var sqlInsert = "insert into buildDetailTable values('";
									sqlInsert += mydata[i].id + "','";
									sqlInsert += mydata[i].documentId + "','";
									sqlInsert += mydata[i].assetId + "','";
									sqlInsert += mydata[i].assetPosition + "','";
									sqlInsert += mydata[i].checkPositionName + "','";
									sqlInsert += mydata[i].assetCode + "','";
									sqlInsert += mydata[i].assetPositionName + "','";
									sqlInsert += mydata[i].documentCode + "','";
									sqlInsert += mydata[i].assetCode + "','";
									sqlInsert += mydata[i].assetName + "','";
									sqlInsert += mydata[i].assetCategoryName + "','";
									sqlInsert += mydata[i].model + "','";
									sqlInsert += mydata[i].assetCount + "','";
									sqlInsert += mydata[i].usingOrgName + "','";
									sqlInsert += mydata[i].usingUserName + "','";
									sqlInsert += mydata[i].realityUsingUser + "','";
									sqlInsert += mydata[i].assetPositionName + "','";
									sqlInsert += mydata[i].checkPositionName + "','";
									sqlInsert += mydata[i].checkDescription + "','";
									sqlInsert += mydata[i].checkUserName + "','";
									sqlInsert += mydata[i].checkResult + "','";
									sqlInsert += mydata[i].checkResult + "','";
									sqlInsert += mydata[i].checkDate + "','";
									sqlInsert += mydata[i].attachFiles + "','";
									sqlInsert += 0 + "','";
									sqlInsert += mydata[i].isPhoto + "'";
									sqlInsert += ')';
									executeSQLNew('nfc', sqlInsert, res4 => {
																
									});
									
							}
							
							if(res2.data.data.total>((current)*100)){
								 self.getLocDetailBuilds(res,current+1)
							}else{
								for (var j = 0; j < listdata.length; j++) {
									//let mydata=mydatamap[listdata[j].id];
									//console.log(listdata[j]);
									let documentid=listdata[j].id;
									let zssql="select * from buildDetailTable where DocumentId='"+documentid+"'";
									executeSQL('nfc', zssql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 盘点总数='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {											
										});
									});
									
									let wpsql="select * from buildDetailTable where DocumentId='"+documentid+"' and 盘点结果='未盘'";
									executeSQL('nfc', wpsql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 未盘='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {
										});
									});
									
									let zcsql="select * from buildDetailTable where DocumentId='"+documentid+"' and 盘点结果='正常'";
									executeSQL('nfc', zcsql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 正常='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {
										});
									});
									
									let ycsql="select * from buildDetailTable where DocumentId='"+documentid+"' and 盘点结果='异常'";
									executeSQL('nfc', ycsql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 异常='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {
										});
									});
									
									let pysql="select * from buildDetailTable where DocumentId='"+documentid+"' and 盘点结果='盘盈'";
									executeSQL('nfc', pysql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 盘盈='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {
										});
									});
									
									let pksql="select * from buildDetailTable where DocumentId='"+documentid+"' and 盘点结果='盘亏'";
									executeSQL('nfc', pksql, wpres => {
										//this.productList = mydata;
										// 接口返回的当前页数据列表 (数组)
										//console.log(wpres);
										let editsql="update MybuildTable set 盘亏='"+wpres.length+"' WHERE Id='"+documentid+"'";
										executeSQL('nfc', editsql, res => {
										});
									});
									
								}
								console.log(123456789);
								commitTransaction('nfc');
								self.jieshumethed("");
							}
							
							
						
						}else{
							uni.showToast({
								icon: 'none',
								title: "暂无数据"
							});
							self.jieshumethed("");
						}					 
					}else{
						uni.showToast({
							icon: 'none',
							title: "请求失败"
						});
						self.jieshumethed( "请求失败");
					}
					}else{
						uni.showToast({
							icon: 'none',
							title: "接口请求超时"
						});
						self.jieshumethed("接口请求超时");
					}
				}).catch(err => {
				  console.error(err);
				uni.showToast({
					icon: 'none',
					title: err
				});
				 
				  
				});
				
				
				
	
				

					
								
							
					
			
				
				
				/*
				uni.getStorage({
					key: 'StockDocumentData',
					success: function(newres) {
						const listdata = newres.data;
						
						beginTransaction('nfc');
						if(listdata.length>0){
						for (var inum = 0; inum < listdata.length; inum++) {
							console.log(listdata[inum].Id);
							uni.request({
								url:uni.getStorageSync("localurl")+'/ServerAPI/Document_Get_Detail_List', //仅为示例，并非真实接口地址。
								data: {
									PdloginName: self.loginName,
									DocumentId: listdata[inum].Id,
									pageSize: 15000,
									_r: "813efd8e-1ac0-4cc8-8c35-3d502f680353",
									pageIndex: 0
								},
								success: res => {

									if (res.data.successed == true) {
										var mydata = [];
										var newrows = JSON.parse(res.data.rows);
										for (var i = 0; i < newrows.length; i++) {
											var valueRows = newrows[i].toString().split(',');
											var datarow = {};
											for (var j = 0; j < res.data.columns.length; j++) {
												//alert(_data.columns[j].字段名)
												datarow[res.data.columns[j].字段名] = valueRows[j];
											}
											mydata.push(datarow);

										}
										//console.log(mydata);
										// var sqlTable2 = 'create table if not exists buildDetailTable("Id" CHAR,"AssetId" CHAR,"Code" CHAR,
										//"StoreCodeName" CHAR,"盘点单编码" CHAR,"资产编码" CHAR,"盘点人" CHAR,"盘点状态" CHAR,
										//"盘点结果" CHAR,"盘点日期" CHAR,"ImgUrl" CHAR)'
										//var SaveStockDocumentCode = uni.getStorageSync('SaveStockDocumentCode');
										console.log(mydata.length);
										for (var i = 0; i < mydata.length; i++) {
											//console.log(mydata[i]);
											//if (SaveStockDocumentCode.indexOf(mydata[i].盘点单编码) == -1) {
												//console.log(mydata[i]);
												//'create table if not exists buildDetailTable(
												//"Id" CHAR,"AssetId" CHAR,"StorePlaceId" CHAR,"PdStorePlaceId" CHAR,"Code" CHAR,"StoreCodeName" CHAR,
												//"盘点单编码" CHAR,"资产编码" CHAR,"资产名称" CHAR,"资产类别" CHAR,"规格型号" CHAR,"数量" CHAR,"使用部门" CHAR,"使用人" CHAR,
												//"盘点使用人" CHAR,"资产位置" CHAR,"盘点位置" CHAR,"盘点备注" CHAR,"盘点人" CHAR,"盘点状态" CHAR,"盘点结果" CHAR,"盘点日期" CHAR,"ImgUrl" CHAR)'
												//executeSQL('nfc', 'delete FROM buildDetailTable where Id="' + mydata[i].Id + '"', res2 => {})
												var sqlInsert = "insert into buildDetailTable values('";
												sqlInsert += mydata[i].Id + "','";
												sqlInsert += mydata[i].DocumentId + "','";
												sqlInsert += mydata[i].AssetId + "','";
												sqlInsert += mydata[i].StorePlaceId + "','";
												sqlInsert += mydata[i].PdStorePlaceId + "','";
												sqlInsert += mydata[i].Code + "','";
												sqlInsert += mydata[i].StoreCodeName + "','";
												sqlInsert += mydata[i].盘点单编码 + "','";
												sqlInsert += mydata[i].资产编码 + "','";
												sqlInsert += mydata[i].资产名称 + "','";
												sqlInsert += mydata[i].资产类别 + "','";
												sqlInsert += mydata[i].规格型号 + "','";
												sqlInsert += mydata[i].数量 + "','";
												sqlInsert += mydata[i].使用部门 + "','";
												sqlInsert += mydata[i].使用人 + "','";
												sqlInsert += "" + "','";
												sqlInsert += mydata[i].资产位置 + "','";
												sqlInsert += mydata[i].盘点位置 + "','";
												sqlInsert += mydata[i].盘点备注信息 + "','";
												sqlInsert += mydata[i].盘点人 + "','";
												sqlInsert += mydata[i].盘点状态 + "','";
												sqlInsert += mydata[i].盘点结果 + "','";
												sqlInsert += mydata[i].盘点日期 + "','";
												sqlInsert += "" + "','";
												sqlInsert += mydata[i].TaskCount + "'";
												sqlInsert += ')';

												executeSQLNew('nfc', sqlInsert, res4 => {

												});

											//}
										}
										mynum++;
										//console.log(inum+"----"+listdata.length+"----"+mynum);
										if(mynum==(listdata.length)){
											self.jieshumethed();
										}

									}
									
								},
								fail: () => {
									//uni.hideNavigationBarLoading();
									uni.showToast({
										icon: 'none',
										title: '网络异常,请稍后重试'
									});
								}
							});
						}
						}else{
							self.jieshumethed();
							}
						
						commitTransaction('nfc');
					}
				});
				*/
			},
		confirm(theme,e){
			var _this = this;
			self=this;
			console.log(e.currentTarget.dataset.id);
			_this.auiDialog.title = '数据同步';
			if(e.currentTarget.dataset.id=="资产台账同步"){				
				_this.auiDialog.msg = '是否开始同步资产台账？';
			}else if(e.currentTarget.dataset.id=="盘点单下载"){				
				_this.auiDialog.msg = '是否开始同步盘点单？';
			}else if(e.currentTarget.dataset.id=="位置信息下载"){				
				_this.auiDialog.msg = '是否开始同步位置信息？';
			}
			
			_this.auiDialog.items = [];
			_this.auiDialog.btns = [
				{name: '取消'},
				{name: '确定'}				
			];
			self.currName=e.currentTarget.dataset.id;
			_this.auiDialog.theme = theme;
			_this.$refs.dialog.show();
		},
		openWin(url, opts){
			aui.openWin(url, opts)
		},
		closeWin(){
			aui.closeWin();
		},
		//dialog弹窗底部按钮回调
		dialogCallback(e){
			self=this;
			var _this = this;
			console.log(e);			
			if(_this.$refs.dialog.getVal().length > 0)
			{ //prompt输入框——点击确定时弹出输入内容
				_this.auiDialog.title = '提示';
				_this.$refs.dialog.getVal().forEach(function(item, index){
					_this.auiDialog.msg += '<div style="display: flex;">' + item.label + '：' + item.value + '</div>';
				});
				_this.auiDialog.btns = [{name: '确定', color: '#197DE0'}];
				_this.auiDialog.items = [];
				_this.auiDialog.theme = 1;
				_this.$refs.dialog.show();
			}
			if(e.msg=="确定"){
				console.log(self.currName);
				if (self.currName == "盘点单下载") {
					uni.setStorageSync("xiazai","1");
					this.dataStock();
					uni.setStorageSync("xiazai","2");
				}
				if (self.currName == "位置信息下载") {
					uni.setStorageSync("xiazai","1");
					this.dataStore();
					uni.setStorageSync("xiazai","2");
				}
				if (self.currName== "资产台账同步") {
					this.dataAsset();
				
				}
				uni.setStorage({
					key:"shuaxinDate",
					data:"1"
				});
			}
			
		},
		Delete(theme){
			var _this = this;
			_this.auiDialog.title = '提示';
			_this.auiDialog.msg = '您点击了delete删除模态弹窗！';
			_this.auiDialog.items = [];
			_this.auiDialog.btns = [
				{name: '取消'},
				{name: '删除'}
			];
			_this.auiDialog.theme = theme;
			_this.$refs.dialog.show();
		},
		filterParentNode(ids,options,options2){
		      if(Array.isArray(ids)&&ids.length>0){
		        options.forEach(option=>{	
					if(ids.includes(option.id)){
						let newoption={
							"id": option.id,
							"code": option.code,
							"label": option.label,
							"isEnabled": option.isEnabled,
							"levelCode": option.levelCode,
							"parentLevelCode": option.parentLevelCode,
							"pathCode": option.pathCode,
							"entityName": option.entityName,
						}							
						let childrenarr=[];
						if(option.children){
						  this.filterParentNode(ids,option.children,childrenarr);
						}
						newoption.children=childrenarr;
						
						options2.push(newoption);
					}else{							
							if(option.children){
								let childrenarr=[];
							  this.filterParentNode(ids,option.children,childrenarr);
							  if(childrenarr.length>0){
								  let newoption={
								  	"id": option.id,
								  	"code": option.code,
								  	"label": option.label,
								  	"isEnabled": "0",
								  	"levelCode": option.levelCode,
								  	"parentLevelCode": option.parentLevelCode,
								  	"pathCode": option.pathCode,
								  	"entityName": option.entityName,
								  }
									newoption.children=childrenarr;
									options2.push(newoption);
							  }
							}
						}
		         
		        });
		      }
		    },
		getNetworkType() {
			//获取网络信息  
			uni.getNetworkType({
				success: res => {
					//this.netWork = res.networkType;
					//console.log(res);
					this.isOpenDB();
				}
			})
		},
		isOpenDB() {
			console.log('是否打开数据库');
			var isOpen = plus.sqlite.isOpenDatabase({
				name: 'nfc', //数据库的名字  
				path: '_doc/nfcList.db' //地址  
			});
			//console.log(!isOpen);
		
			if (!isOpen) {
				//console.log('Unoepned:' + isOpen);
				// plus.nativeUI.alert('Unopened!');  
				this.openDB(); //打開DB  
			} else {
				// plus.nativeUI.alert('Opened!');  
				//this.isNet();
				// this.getLocalType();  
			}
		},
		openDB() {
			//SQLite      
			openComDB('nfc', '_doc/nfcList.db', res => {
				console.log('打开数据库');
				this.createBuildTable();
			});
		},
		
		request_tool(options){
		 // 在这里可以对请求头进行一些设置
		 let baseUrl = uni.getStorageSync("localurl"); 
		
	
		
		 
		
		  options.header = {
		      'Content-Type':'application/json',
		      Authorization: uni.getStorageSync("authorization")
		 }
		//console.log(options);
		    return new Promise((resolve, reject) => {
		        uni.request({
		            url: baseUrl + options.url || '',
		            method: options.type || 'POST',
		            data: options.data || {},
		            header: options.header || {}      
		        }).then(data => {
		            let [err, res] = data;        
		            resolve(res);
		        }).catch(error => {
		            reject(error)
		        })
		    });
		}
		}
	}
</script>

<style>
	.content {
		background-color: #edf1f4 !important;
	}
	.dataUpdata {
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		top: 45%;
		left: 25%;
		transform: translate(-25%, -45%);
		padding: 0 15%;
background-color: #edf1f4;
	}

	.dataUpdata .pview {
		color: #6D8AF9;
		width: 100%;
	}

	.dataUpdata .liview .preloader,
	.liview.active .data-update-time {
		display: none;
	}

	.dataUpdata .liview .data-update-time {
		color: #999;
	}


	.list {
		float: left;
	}

	.list .liview {
		float: left;
		width: 500upx;
	}

	.footer {}

	.footer .button {
		float: left;
		width: 100rpx;
		background-color: #6D8AF9;
		height: 62rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 62rpx;
		border-radius: 10rpx;
		margin-top: -10rpx;
	}

	.item-text {
		height: 160rpx;
		line-height: 80rpx;
		border: 1rpx #BEBEBE solid;
		width: 70%;
		text-align: center;
		margin-left: 15%;
		margin-top: 70rpx;
		background-color: #6D8AF9;
		border-radius: 50rpx;
		color: #FFFFFF;
	}
</style>
